package com.ajaxw.img;

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;

public class CreateImage {
	private BufferedImage bufImg;
	private Graphics2D graph2;

	public void setFg(Color fg) {
		this.graph2.setPaint(fg);
	}

	public CreateImage(int width, int height) {
		this.bufImg = new BufferedImage(width, height,
				BufferedImage.TYPE_INT_RGB);
		this.graph2 = (Graphics2D) this.bufImg.getGraphics();
		this.graph2.setRenderingHint(RenderingHints.KEY_RENDERING,
				RenderingHints.VALUE_RENDER_QUALITY);
		this.graph2.setBackground(Color.WHITE);
		this.graph2.clearRect(0, 0, width, height);
		this.graph2.setPaint(Color.WHITE);
	}

	public void setPoint(int x, int y) {
		this.graph2.fillRect(x, y, 1, 1);
	}

	public void setPoint(Point pos) {
		this.graph2.fillRect(pos.x, pos.y, 1, 1);
	}

	public void setPoint(java.util.List<Point> pnts) {
		for (Point pos : pnts)
			this.graph2.fillRect(pos.x, pos.y, 1, 1);
	}

	public void save2File(String file) throws IOException {
		ImageIO.write(this.bufImg, "bmp", new File(file));
	}
}
